package com.example.server.plugins

import com.example.commons.serialization.DateSerializer
import com.example.commons.serialization.DateTimeSerializer
import com.example.commons.serialization.TimeSerializer
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*
import kotlinx.serialization.json.Json
import kotlinx.serialization.modules.SerializersModule
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.LocalTime

fun Application.configureSerialization() {
    install(ContentNegotiation) {
        json(
            Json {
                serializersModule = SerializersModule {
                    contextual(LocalDate::class, DateSerializer())
                    contextual(LocalDateTime::class, DateTimeSerializer())
                    contextual(LocalTime::class, TimeSerializer())
                }
                encodeDefaults = true
            }
        )
    }
}
